// 层序遍历 BFS
// 通常借助队列的先入先出特性来实现
var levelOrder = function (root) {
  if (!root) return [];
  let res = [],
      queue = [root];
  while (queue.length) {
    let cur = queue.shift();
    res.push(cur.val);
    cur.left && queue.push(cur.left);
    cur.right && queue.push(cur.right);
  }
  return res;
}